//
//  MainViewController.m
//  Homestay
//
//  Created by admin on 2017/3/14.
//  Copyright © 2017年 ysln. All rights reserved.
//

#import "MainView.h"
#import "MainViewController.h"
#import "LoginViewController.h"
#import "RegisterViewController.h"
#import "MainTabBarController.h"
#import "MainTabBarController.h"

@interface MainViewController ()

@property(nonatomic , strong)MainView *mainView;

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:[self mainView]];
    
    
}

-(MainView *)mainView{
    
    if (!_mainView) {
        
        _mainView = [[MainView alloc] initWithFrame:self.view.frame];
        [_mainView.loginBtn addTarget:self action:@selector(pushLogin:) forControlEvents:UIControlEventTouchUpInside];
        [_mainView.regiserBtn addTarget:self action:@selector(pushRegister:) forControlEvents:UIControlEventTouchUpInside];
        [_mainView.goFirst addTarget:self action:@selector(goFirst:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _mainView;
}


-(void)goFirst:(UIButton *)sender{
    
    MainTabBarController *vc = [[MainTabBarController alloc] init];
    [self presentViewController:vc animated:YES completion:nil];
}

-(void)pushRegister:(UIButton *)sender{
    
    RegisterViewController *vc = [[RegisterViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    [self presentViewController:nav animated:YES completion:nil];
    
    
}

-(void)pushLogin:(UIButton *)sender{
    
    LoginViewController *vc = [[LoginViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    [self presentViewController:nav animated:YES completion:nil];
    
}

- (void)viewWillAppear:(BOOL)animated{
    
    
    //设置导航栏背景图片为一个空的image，这样就透明了
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    //去掉透明后导航栏下边的黑边
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
    
}

- (void)viewWillDisappear:(BOOL)animated{
    
    //    如果不想让其他页面的导航栏变为透明 需要重置
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
